package cn.weakup.designpattern.d_behavior.strategy.usepattern;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author lixj
 * @version 1.0.0
 * @date 2022/6/2
 * @desc 满减算法
 */
public class EnoughCouponDiscount implements ICouponDiscount<Map<String, String>>{
    /**
     * 满减⾦额计算
     *
     * @param couponInfo 满减信息
     * @param totalPrice 原商品总价
     * @return 优惠价
     */
    @Override
    public BigDecimal discountAmount(Map<String, String> couponInfo, BigDecimal totalPrice) {
        BigDecimal enoughPrice = new BigDecimal(couponInfo.get("enoughPrice"));
        // 没达到满减金额，返回原总价
        if(enoughPrice.compareTo(totalPrice) < 0) {
            return totalPrice;
        } else {
            BigDecimal discount = new BigDecimal(couponInfo.get("discount"));
            return totalPrice.subtract(discount);
        }
    }
}
